<?php

class Sgit_Util_OrderArray
{


    static function run($data, $field,$inverse = false)
    {
        if (!is_array($field))
            $field = array($field);
            
        

        usort($data, 
            function ($a, $b)use ($field)
            {
                $retval = 0; 
                foreach ($field as $fieldname)
                {
                    if ($retval == 0)
                        $retval = strnatcmp($a[$fieldname], $b[$fieldname]) ; 
                }
                return $retval; 
            }
        );
        
        if($inverse)
            $data=array_reverse($data);
            
        return $data;
    }


    /*
    static function run($toOrderArray, $field, $inverse = false)
    {
    $position = array();
    $newRow = array();

    foreach ($toOrderArray as $key => $row)
    {
    $position[$key] = $row[$field];
    $newRow[$key] = $row;
    }

    if ($inverse)
    {
    arsort($position);
    } else
    {
    asort($position);
    }
    $returnArray = array();
    foreach ($position as $key => $pos)
    {
    $returnArray[] = $newRow[$key];
    }
    return $returnArray;


    }*/

}
